import 'package:common_utils/common_utils.dart';
import 'package:erp/main_state.dart';
import 'package:erp/res/colors.dart';
import 'package:erp/widgets/form1/field/selector.dart';
import 'package:erp/widgets/form1/form_builder.dart';
import 'package:erp/widgets/my_app_bar.dart';
import 'package:erp/widgets/my_button.dart';
import 'package:erp/widgets/process_attachment_list.dart';
import 'package:erp/widgets/sale_project_detail_list.dart';
import 'package:erp/widgets/sale_project_title.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import 'controller.dart';

export 'binding.dart';

class SaleProjectHandle extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    var ms = Get.find<MainState>();
    var controller = Get.find<SaleProjectHandleController>();
    return Scaffold(
      backgroundColor: Colours.bg_color,
      appBar: MyAppBar(
        centerTitle: '流程办理',
        titleColor: Colors.black,
      ),
      body: ListView(
        children: [
          SaleProjectTile(title: '申请信息', padding: EdgeInsets.only(left: 52.w)),
          Container(
            color: Colors.white,
            padding: EdgeInsets.symmetric(horizontal: 52.w),
            child: FormBuilder(
              readOnly: true,
              formManagement: FormManagement(),
              initialValue: controller.saleProjectData,
              children: [
                OptionSelectorFormField(
                  label: '* 所属公司',
                  name: 'company',
                  options: ms.getOptions('company'),
                  validator: (value) {
                    if (ObjectUtil.isEmpty(value)) {
                      return "所属公司不能为空";
                    }
                  },
                ),
                ClearableTextFormField(
                  label: '* 项目名称',
                  name: 'projectName',
                  validator: (value) {
                    if (ObjectUtil.isEmpty(value)) {
                      return "项目名称不能为空";
                    }
                  },
                ),
                ClearableTextFormField(
                  label: '* 立项编号',
                  name: 'projectNo',
                  validator: (value) {
                    if (ObjectUtil.isEmpty(value)) {
                      return "立项编号不能为空";
                    }
                  },
                ),
                ClearableTextFormField(
                  label: '* 销售经理(申请人)',
                  name: 'applyEmp',
                  validator: (value) {
                    if (ObjectUtil.isEmpty(value)) {
                      return "销售经理(申请人)不能为空";
                    }
                  },
                ),
                ClearableTextFormField(
                  label: '* 市场区域',
                  name: 'marketArea',
                  validator: (value) {
                    if (ObjectUtil.isEmpty(value)) {
                      return "市场区域不能为空";
                    }
                  },
                ),
                OptionSelectorFormField(
                  label: '* 所属大区',
                  name: 'areaDept',
                  options: ms.getOptions('area_dept'),
                  validator: (value) {
                    if (ObjectUtil.isEmpty(value)) {
                      return "所属大区不能为空";
                    }
                  },
                ),
                OptionSelectorFormField(
                  label: '* 投标状态',
                  name: 'bidStatus',
                  options: ms.getOptions('bid_status'),
                  validator: (value) {
                    if (ObjectUtil.isEmpty(value)) {
                      return "投标状态不能为空";
                    }
                  },
                ),
              ],
            ),
          ),
          SaleProjectTile(title: '市场立项项目信息', padding: EdgeInsets.only(left: 52.w)),
          Container(
            color: Colors.white,
            padding: EdgeInsets.symmetric(horizontal: 52.w),
            child: FormBuilder(
              readOnly: true,
              formManagement: FormManagement(),
              initialValue: controller.saleProjectData,
              children: [
                ClearableTextFormField(
                  label: '* 业主单位',
                  name: 'ownUnit',
                  validator: (value) {
                    if (ObjectUtil.isEmpty(value)) {
                      return "业主单位不能为空";
                    }
                  },
                ),
                ClearableTextFormField(
                  label: '* 设计单位',
                  name: 'designUnit',
                  validator: (value) {
                    if (ObjectUtil.isEmpty(value)) {
                      return "设计单位不能为空";
                    }
                  },
                ),
                ClearableTextFormField(
                  label: '* 总承包单位',
                  name: 'contractUnit',
                  validator: (value) {
                    if (ObjectUtil.isEmpty(value)) {
                      return "总承包单位不能为空";
                    }
                  },
                ),
                ClearableTextFormField(
                  label: '* 招标单位',
                  name: 'bidUnit',
                  validator: (value) {
                    if (ObjectUtil.isEmpty(value)) {
                      return "招标单位不能为空";
                    }
                  },
                ),
                ClearableTextFormField(
                  label: '* 建设地点',
                  name: 'buildAddress',
                  validator: (value) {
                    if (ObjectUtil.isEmpty(value)) {
                      return "招建设地点不能为空";
                    }
                  },
                ),
                ClearableTextFormField(
                  label: '* 建设阶段',
                  name: 'buildStage',
                  validator: (value) {
                    if (ObjectUtil.isEmpty(value)) {
                      return "建设阶段不能为空";
                    }
                  },
                ),
                DateSelectorFormField(
                  label: '* 启动时间',
                  name: 'beginTime',
                  validator: (value) {
                    if (ObjectUtil.isEmpty(value)) {
                      return "启动时间不能为空";
                    }
                  },
                ),
                DateSelectorFormField(
                  label: '* 预竣工时间',
                  name: 'endTime',
                  validator: (value) {
                    if (ObjectUtil.isEmpty(value)) {
                      return "预竣工时间不能为空";
                    }
                  },
                ),
                ClearableTextareaFormField(
                  label: '* 工期说明',
                  name: 'buildDesc',
                  validator: (value) {
                    if (ObjectUtil.isEmpty(value)) {
                      return "工期说明不能为空";
                    }
                  },
                ),
                OptionSelectorFormField(
                  label: '* 建设方式',
                  name: 'buildType',
                  options: ms.getOptions('build_type'),
                  validator: (value) {
                    if (ObjectUtil.isEmpty(value)) {
                      return "建设方式不能为空";
                    }
                  },
                ),
                OptionSelectorFormField(
                  label: '* 项目类别',
                  name: 'projectCategory',
                  options: ms.getOptions('project_category'),
                  validator: (value) {
                    if (ObjectUtil.isEmpty(value)) {
                      return "项目类别不能为空";
                    }
                  },
                ),
                OptionSelectorFormField(
                  label: '* 主要负责技术部',
                  name: 'chargeDept',
                  options: ms.getOptions('charge_dept'),
                  validator: (value) {
                    if (ObjectUtil.isEmpty(value)) {
                      return "主要负责技术部不能为空";
                    }
                  },
                ),
              ],
            ),
          ),
          SaleProjectTile(title: '项目详细情况', padding: EdgeInsets.only(left: 52.w)),
          Container(
            color: Colors.white,
            padding: EdgeInsets.fromLTRB(34.w, 0, 34.w, 20.h),
            child: SaleProjectDetailList(
              saleProjectDetailList: controller.saleProjectDetails,
              readOnly: true,
              onCheck: (item) {
                controller.seeProjectDetail(item);
              },
            ),
          ),
          SaleProjectTile(title: '主要商务情况', padding: EdgeInsets.only(left: 52.w)),
          Container(
            color: Colors.white,
            padding: EdgeInsets.symmetric(horizontal: 52.w),
            child: FormBuilder(
              readOnly: true,
              formManagement: FormManagement(),
              initialValue: controller.saleProjectData,
              children: [
                OptionSelectorFormField(
                  label: '* 项目来源',
                  name: 'projectSource',
                  options: ms.getOptions('project_source'),
                  validator: (value) {
                    if (ObjectUtil.isEmpty(value)) {
                      return "项目来源不能为空";
                    }
                  },
                ),
                OptionSelectorFormField(
                  label: '* 项目招投标方式',
                  name: 'bidMode',
                  options: ms.getOptions('bid_mode'),
                  validator: (value) {
                    if (ObjectUtil.isEmpty(value)) {
                      return "项目招投标方式不能为空";
                    }
                  },
                ),
                FilterChipFormField(
                  items: controller.docListItems,
                  label: "* 需要材料",
                  name: 'docList',
                  validator: (value) {
                    if (ObjectUtil.isEmpty(value)) {
                      return "需要材料不能为空";
                    }
                  },
                ),
                ClearableTextFormField(
                  label: '其他材料',
                  name: 'otherDoc',
                ),
              ],
            ),
          ),
          SaleProjectTile(title: '流程附件', padding: EdgeInsets.only(left: 52.w)),
          Container(
            color: Colors.white,
            padding: EdgeInsets.fromLTRB(52.w, 0, 52.w, 20.h),
            child: ProcessAttachmentList(
              processFileList: controller.processAttachmentList,
            ),
          ),
          SaleProjectTile(title: '流程审批', padding: EdgeInsets.only(left: 52.w)),
          Container(
            color: Colors.white,
            padding: EdgeInsets.symmetric(horizontal: 52.w),
            child: Obx(
              () => FormBuilder(
                initialValue: controller.initialValues,
                formManagement: controller.formManagement,
                children: [
                  controller.nodeAuth == 1
                      ? ClearableTextFormField(
                          label: '* 项目利润指标',
                          name: 'projectProfitRate',
                          placeholder: "元",
                          validator: (value) {
                            if (ObjectUtil.isEmpty(value)) {
                              return "项目利润指标不能为空";
                            }
                            return null;
                          },
                        )
                      : SizedBox.shrink(),
                  controller.nodeAuth == 1
                      ? ClearableTextFormField(
                          label: '* 市场营销费用额度',
                          name: 'projectExpenseAmount',
                          placeholder: "元",
                          validator: (value) {
                            if (ObjectUtil.isEmpty(value)) {
                              return "市场营销费用额度不能为空";
                            }
                            return null;
                          },
                        )
                      : SizedBox.shrink(),
                  RadioGroupFormField<String>(
                    label: '* 审批结果',
                    name: "handleResult",
                    items: controller.radioItems,
                    onChange: (value) {
                      controller.handleResult.value = value;
                      print(value);
                    },
                  ),
                  ClearableTextareaFormField(
                    label: (controller.handleResult == 'NO' ? '* ' : '') + '审批意见',
                    placeholder: '请输入审批意见...',
                    name: 'handleContent',
                    validator: controller.handleResult == 'NO'
                        ? (value) {
                            if (ObjectUtil.isEmpty(value)) {
                              return "审批意见不能为空";
                            }
                          }
                        : null,
                  ),
                  SizedBox(height: 40.h),
                ],
              ),
            ),
          ),
          SizedBox(height: 82.h),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              MyButton(
                onPressed: () {
                  controller.cancel();
                },
                text: '取消',
                textColor: Color(0xff666666),
                fontSize: 34.sp,
                radius: 40.r,
                backgroundColor: Colors.white,
                minWidth: 230.w,
                side: BorderSide(color: Color(0xff4C88FF), width: 1.w, style: BorderStyle.solid),
                minHeight: 80.h,
              ),
              SizedBox(width: 36.w),
              MyButton(
                onPressed: () {
                  controller.next();
                },
                textColor: Colors.white,
                backgroundColor: Color(0xff3388FF),
                text: '确认转交下一步',
                minWidth: 380.w,
                fontSize: 34.sp,
                minHeight: 80.h,
                radius: 40.r,
              )
            ],
          ),
          SizedBox(height: 135.h)
        ],
      ),
    );
  }
}
